<?
session_start();
$pagename=LA_NOTIFY;
include_once("header_inc.php");
check_valid_user("");
include_once("member_header.php");
$valid_user = $_SESSION["valid_user"];
$tplNotify=new TplLoad;

if (getParam("submit",""))
{
	q("delete from $not_tbl where notify_user_id=" . $_SESSION["valid_user"]);
	
	$catid_rem=$_REQUEST["catid_rem"];
	if (is_array($catid_rem))
	{
		foreach ($catid_rem as $item)
		{
			$sql="insert into $not_tbl (notify_user_id,notify_cat) values (".$_SESSION["valid_user"].",$item)";
			$r=q($sql);
		}
	}
	$tplNotify->assign("notify_saved",1);
	addToHistory(11,$_SESSION["valid_user"],"","");
}

$sql="select notify_cat from $not_tbl where notify_user_id=" . $_SESSION["valid_user"];
$res=q($sql);
$lCurrentSubscribedArray[]="";
while ($row_user=mysql_fetch_array($res))
{
	$lCurrentSubscribedArray[]=$row_user["notify_cat"];
}

$sql="select * from $cat_tbl where cat_allow_ads='on'";
$res=q($sql);

$i=0;
$lItemCount=0;
$divide=mysql_num_rows($res);

if ($divide>0)
	$divide=round($divide/4);

while ($row=mysql_fetch_array($res))
{
	$lItemCount++;
	$catname=$row["cat_name"];
	if (!empty($_SESSION["la"]) AND $set_multilang_cat)
	{
		$lang_cat = "lang_" . $_SESSION["la"];
	
		if (!empty($row["$lang_cat"]))
			$catname = $row["$lang_cat"];
	}
	$listArray[$i]["catname"]=$catname;
	$listArray[$i]["catid"]=$row["cat_id"];
	if (in_array($row["cat_id"],$lCurrentSubscribedArray))
		$listArray[$i]["checked"]=" checked";
	if ($lItemCount==$divide)
	{
		$listArray[$i]["divide"]=1;
		$lItemCount=0;
	}
	$i++;
}
$lCatTreeParent=getParamInt("cat_tree_parent","0");
$tplNotify->assign("parent",$lCatTreeParent);
$tplNotify->assign("tree_name", "notify");
$lCatTree=build_cat_tree($lCatTreeParent,"notify",3);
$tplNotify->assign("tree",$lCatTree);
$tplNotify->assign("listArray",$listArray);

$tplNotify->display("member_notify.tpl");
include_once("member_footer.php");
include_once("footer_inc.php");
?>